import sys, numpy, copy, re

in_file_name = None

def create_problem(infile):
    """ Puts all the job/resource combinations into a list
        and initializes global parameters
    """
    global n, m, problem
    problem_description = infile.readline()
    n, m = infile.readline().split()
    n = int(n)
    m = int(m)
    durations = []
    for job_id, line in enumerate(infile):
        if not line.isspace():
            line_iter = iter(line.split())
            for r in xrange(m):
                machine_id = int(line_iter.next())
                duration = int(line_iter.next())
                durations.append(duration)
    stdev = numpy.std(durations)
    m = numpy.mean(durations)
    khaki = n * m * stdev / m
    fname = copy.copy(in_file_name)
    fname = re.sub('cs540-jsp/', '', fname)
    fname = re.sub('.inst.txt', '', fname)
    fname = re.sub('.txt', '', fname)
    with open('mucsi-khaki.csv', 'a') as out:
        out.write('%s,%s\n' % (fname, str(round(khaki,0))))

if __name__ == '__main__':
    program_name, in_file_name = sys.argv
    with open(in_file_name) as in_file:
        create_problem(in_file)